const http = uni.$u.http
import Store from "@/store/index"

import {
	// http,
	handleParams,
	formatGetParams
} from "@/utils/http/tool"

import {
	userRoutes,
	processorRoutes,
	adminRoutes
} from "../routeDatas"

// const url = http://192.168.0105:8080/data/img
// img :[
// 	{
// 		path":"D:  abc"
// 		"fileF":".jpg"
// 		"size"."289.89KB"
// 		"name":"1678094840426 944.jpg"
// 		"url":"/data/img/2023030
// 	},
// 	{
// 		path":"D:  abc"
// 		"fileF":".jpg"
// 		"size"."289.89KB"
// 		"name":"1678094840426 944.jpg"
// 		"url":"http://192.168.0105:8080/data/img/2023030
// 	}
// ]

/**
 * @description 登录
 * @param {Object}        params 参数对象
 * @param {Number|String} params[username] 账号就是手机号
 * @param {Number}        params[password] 密码
 * @param {Object}        config 配置参数(可选)
 * @param {Object}        config[custom] 自定义参数
 * @param {Boolean}       config[custom][loading] 显示加载中
 * @param {Boolean}       config[custom][auth] 添加token
 * @param {Boolean}       config[custom][toast] 错误轻提示
 * @param {Boolean}       config[custom][catch] 返回catch
 */
export const login = (params, config = {
	custom: {
		auth: false
	}
}) => {
	return http.post(`/weChatLogin`, params, handleParams(config));
	return new Promise((resovle) => {
		resovle({
			bs: "1",
			code: 200,
			msg: "操作成功",
			token: "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQ5ZDZmYmIyLWVkOTMtNGE0MC1hYWJlLWQ0NzMwMDQ1NDU3MyJ9.SMtt4Md2HoxdvJHSgHFTigNGqSppBGaOnxFgZ6eBeXATr2Z11outeHnM28rJXGIaqznsz5hVtO9NhatpfmINNA",
			user: [{
				email: "",
				phonenumber: "18999999999",
				role_key: "appletuser",
				role_name: "小程序用户",
				sex: "0",
				user_id: 14,
				user_name: "18999999999",
				user_type: "02",
			}]

		})
	})
}

/**
 * @description 注册/忘记密码
 * @param {Object}        params 参数对象
 * @param {Number|String} params[username] 帐号(手机号)
 * @param {NString}       params[password] 原密码
 * @param {NString}       params[newpassword] 新密码
 * @param {Number}        params[flag] 状态（1是注册，2是忘记密码)
 */
export const retrieve = (params, config = {
	custom: {
		auth: false
	}
}) => http.post(`/RegistrationPassword`, params, handleParams(config))

/**
 * @description 发送验证码
 * @param {Object}        params 参数对象
 * @param {Number|String} params[phone] 手机号
 * @param {Number}        params[flag] 状态（1是注册，2是忘记密码)
 */
export const pushCode = (params, config = {
	custom: {
		auth: false
	}
}) => http.post(`/verification`, params, handleParams(config))

/**
 * @description 校验验证码
 * @param {Object}        params 参数对象
 * @param {Number|String} params[phone] 手机号
 * @param {Number}        params[verification] 验证码
 */
export const verificationCode = (params, config = {
	custom: {
		auth: false
	}
}) => http.post(`/weChatVerification`, params, handleParams(config))


/**
 * @description 动态获取路由
 * @param {String} roleKey 角色id
 */
export const getRoutes = (params, config = {
	custom: {
		loading: false
	}
}) => {
	// 正式版 
	// return http.post(`weChatAppUser/weChatMenu`, params, handleParams(config))
	// 临时测试用 
	const roleId = Store.state.user.userInfo.roleId
	if (roleId === 3) return http.post(`weChatAppUser/weChatMenu`, params, handleParams(config))
	else return new Promise((resolve) => {
		resolve({
			code: 200,
			data: adminRoutes
		})
	})
}

// 获取图形验证码
export const getCodeImg = (params, config = {
	custom: {
		auth: false,
		loading: false
	}
}) => http.get(`/captchaImage`, formatGetParams({
	params,
	config
}))